// 主题匹配算法
bool topicMatchesFilter(String topic, String filter) {
  final filterSegments = filter.split('/');
  final topicSegments = topic.split('/');
  for (int i = 0; i < filterSegments.length; i++) {
    final segment = filterSegments[i];
    if (segment == '#') return true;
    if (i >= topicSegments.length) return false;
    if (segment != '+' && segment != topicSegments[i]) return false;
  }

  return filterSegments.length == topicSegments.length;
}
